1475B - New Year's Number - CodeForces Solution


brute force dp math *900

Please click on ads to support us..

Python Code:

t=int(input())

for i in range(t):
    n=int(input())
    
    m=n%2020
    d=n//2020

    if(m<=d):
        print("YES")
    
    else:
        print("NO")

C++ Code:

#include <bits/stdc++.h>
#define ll             long long
#define pb             push_back
#define ld             long double
#define lala           for(ll i=0;i<n;i++)
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
using namespace std;
const int MOD = 1e9 + 7;
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
void vin( vector<int> &v , int n ){for (int i = 0; i < n; i++){int x ;cin >> x; v.push_back(x);}}
void vout(vector<int> &v){for (int i = 0; i < v.size(); i++){cout << v[i] << " " ;}cout << endl;}
long long lcm(int a, int b){    return (a / gcd(a, b)) * b;}
int digits_count(int n){int d=0;while(n != 0){d++;n /=10;}return d;}

vi dp(1e6+1,-1);
bool rec(int n)
{
    if(n<2020) return 0;
    if(n==2021 || n==2020) return 1;
    if(dp[n]!=-1) return dp[n];
    return dp[n]=(rec(n-2020) || rec(n-2021));
}

void hello()
{
    ll n;
    cin>>n;
    // cout<<rec(n)<<endl;
    if(rec(n)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}
int main()
{
    int t=1;
    cin>>t;
    while(t--)
    {
        hello();
    }
}


Comments

Submit
0 Comments
More Questions

1029A - Many Equal Substrings
1675D - Vertical Paths
1271C - Shawarma Tent
805A - Fake NP
1163A - Eating Soup
787A - The Monster
807A - Is it rated
1096A - Find Divisible
1430C - Numbers on Whiteboard
1697B - Promo
208D - Prizes Prizes more Prizes
659A - Round House
1492C - Maximum width
171B - Star
1512B - Almost Rectangle
831B - Keyboard Layouts
814A - An abandoned sentiment from past
268C - Beautiful Sets of Points
1391C - Cyclic Permutations
11A - Increasing Sequence
1406A - Subset Mex
1365F - Swaps Again
50B - Choosing Symbol Pairs
1719A - Chip Game
454B - Little Pony and Sort by Shift
1152A - Neko Finds Grapes
1719B - Mathematical Circus
1719C - Fighting Tournament
1642A - Hard Way
285C - Building Permutation